package top.readhub.wopei.client.helper;

import top.readhub.wopei.client.loader.LocalLoader;
import top.readhub.wopei.client.loader.ServiceLoader;
import top.readhub.wopei.client.loader.ZKLoader;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by daervin on 2021/6/11
 */
public class InstHelper {
    private InstHelper() {

    }

    private static AtomicBoolean flag = new AtomicBoolean(false);
    private static LocalLoader localLoader;
    private static ZKLoader zkLoader;
    private static ServiceLoader serviceLoader;

    private static void init() {
        if (flag.get()) {
            return;
        }
        synchronized (InstHelper.class) {
            if (flag.get()) {
                return;
            }
            zkLoader = new ZKLoader();
            localLoader = new LocalLoader(zkLoader);
            serviceLoader = new ServiceLoader();
            flag.set(true);
        }
    }

    public static LocalLoader getLocalLoader() {
        init();
        return localLoader;
    }

    public static ZKLoader getZkLoader() {
        init();
        return zkLoader;
    }

    public static ServiceLoader getServiceLoader() {
        init();
        return serviceLoader;
    }
}
